 class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
}

public class KthtoLast {
    public  int kthtoLast(ListNode head,int k){
        if(k<=0) {
            return -1;
        }
        ListNode fast=head;
        ListNode slow=head;
        int count=0;
        while(count!=k-1){
            if(fast==null){
                return -1;
            }
            fast=fast.next;
            count++;
        }
        while(fast.next!=null){
            slow=slow.next;
            fast=fast.next;
        }
        return slow.val;
    }
}